﻿using ZYCommon;
using System;

namespace TextEditor
{
    

    public class ZYKBObjectList : ObjectByteList
    {
        public bool ClearSEQ = true;
        public KB_List RootKBList = null;

        public override object BytesToObject(int ClassID)
        {
            switch (ClassID)
            {
                case 0:
                {
                    KB_List list = new KB_List();
                    list.SEQ = base.ReadString();
                    list.ParentSEQ = base.ReadString();
                    list.Name = base.ReadString();
                    list.Desc = base.ReadString();
                    list.ListIndex = base.ReadInt32();
                    list.ListSQL = base.ReadString();
                    list.KBStyle = base.ReadInt32();
                    list.KBGroup = base.ReadString();
                    return list;
                }
                case 1:
                {
                    KB_Item item = new KB_Item();
                    item.ItemSEQ = base.ReadInt32();
                    item.KBSEQ = base.ReadString();
                    item.ItemText = base.ReadString();
                    item.ItemValue = base.ReadString();
                    item.ItemDesc = base.ReadString();
                    item.ListIndex = base.ReadInt32();
                    item.ItemStyle = base.ReadInt32();
                    return item;
                }
                case 2:
                {
                    ET_Document document = new ET_Document();
                    document.ObjectID = base.ReadString();
                    document.ObjectName = base.ReadString();
                    document.ObjectType = base.ReadInt32();
                    document.ObjectData = base.ReadString();
                    return document;
                }
                case 3:
                {
                    KBSection section = new KBSection();
                    section.KBSEQ = base.ReadString();
                    section.OwnerSection = base.ReadString();
                    return section;
                }
            }
            return null;
        }

        private KB_List GetKBList(string strSEQ)
        {
            foreach (object obj2 in this)
            {
                if ((obj2 is KB_List) && ((obj2 as KB_List).SEQ == strSEQ))
                {
                    return (obj2 as KB_List);
                }
            }
            return null;
        }

        public override bool ObjectToBytes(object objData, ref int ClassID)
        {
            if (objData is KB_List)
            {
                ClassID = 0;
                KB_List list = (KB_List) objData;
                base.AppendObjectData(list.SEQ);
                base.AppendObjectData(list.ParentSEQ);
                base.AppendObjectData(list.Name);
                base.AppendObjectData(list.Desc);
                base.AppendObjectData(list.ListIndex);
                base.AppendObjectData(list.ListSQL);
                base.AppendObjectData(list.KBStyle);
                base.AppendObjectData(list.KBGroup);
                return true;
            }
            if (objData is KB_Item)
            {
                ClassID = 1;
                KB_Item item = (KB_Item) objData;
                base.AppendObjectData(item.ItemSEQ);
                base.AppendObjectData(item.KBSEQ);
                base.AppendObjectData(item.ItemText);
                base.AppendObjectData(item.ItemValue);
                base.AppendObjectData(item.ItemDesc);
                base.AppendObjectData(item.ListIndex);
                base.AppendObjectData(item.ItemStyle);
                return true;
            }
            if (objData is ET_Document)
            {
                ClassID = 2;
                ET_Document document = (ET_Document) objData;
                base.AppendObjectData(document.ObjectID);
                base.AppendObjectData(document.ObjectName);
                base.AppendObjectData(document.ObjectType);
                base.AppendObjectData(document.ObjectData);
                return true;
            }
            if (objData is KBSection)
            {
                ClassID = 3;
                KBSection section = (KBSection) objData;
                base.AppendObjectData(section.KBSEQ);
                base.AppendObjectData(section.OwnerSection);
                return true;
            }
            return false;
        }
    }
}

